#{extends "main.html" /}

#{set title: entity ? "TA014 DETAIL " + entity.getSplit_template_name() : "Create New Template" /}

#{set entityId: entity ? entity.id : "" /}

#{form @controllers.SplitTemplate.save()}
<p>
    <input type="submit" class="btn btn-primary" name="save" value="Save"/>
    #{if entity}
        <a href="@{controllers.Bind.template(entity.id)}" role="button" class="btn btn-primary" target="_blank">Bind Aircrafts</a>
        <a href="@{controllers.ReformatTemplate.edit(null, entity.id)}" role="button" class="btn btn-primary" target="_blank">Add Reformat Template</a>
    #{/if}
</p>
<input type="hidden" name="id" value="${entityId}"/>
<div class="col-md-8">
    <div class="form-row">

        <div class="form-group col-md-8">
            <label for="split_template_name" class="text-capitalize">template name</label>
            <input type="text" class="form-control" id="split_template_name" name="entity.split_template_name" value="${entity ? entity.split_template_name : ''}"/>
        </div>
        <div class="form-group col-md-4">
            <label for="type" class="text-capitalize">type</label>
            <input type="text" class="form-control" id="type" name="entity.type" value="${entity ? entity.type : ''}"/>
        </div>

    </div>
    <div class="form-row">
        <div class="form-group col">
            <label for="aviation" class="text-capitalize">aviation</label>
            <input type="text" class="form-control" id="aviation" name="entity.aviation" value="${entity ? entity.aviation : ''}"/>
        </div>
        <div class="form-group col">
            <label for="department" class="text-capitalize">department</label>
            <input type="text" class="form-control" id="department" name="entity.department" value="${entity ? entity.department : ''}"/>
        </div>
        <div class="form-group col">
            <label for="signer" class="text-capitalize">signer</label>
            <input type="text" class="form-control" id="signer" name="entity.signer" value="${entity ? entity.signer : ''}"/>
        </div>
    </div>
    <div class="form-row">
        <div class="form-group col">
            <label for="smi" class="text-capitalize">smi</label>
            <input type="text" class="form-control" id="smi" name="entity.smi" value="${entity ? entity.smi : ''}"/>
        </div>
        <div class="form-group col">
            <label for="marker" class="text-capitalize">marker</label>
            <input type="text" class="form-control" id="marker" name="entity.marker" value="${entity ? entity.marker : ''}"/>
        </div>
        <div class="form-group col">
            <label for="marker_pos" class="text-capitalize">marker pos</label>
            <input type="text" class="form-control" id="marker_pos" name="entity.marker_pos" value="${entity ? entity.marker_pos : ''}"/>
        </div>
    </div>

    <div class="form-group">
        <label for="template" class="text-capitalize">template</label>
        <textarea id="template" name="entity.template" rows="15" class="form-control">${entity ? entity.template : ''}</textarea>
        <small class="text-muted ">last modified: ${entity ? entity.last_update : ''}</small>
    </div>

    <div class="form-group">
        <label for="datagramText" class="text-capitalize">datagram sample</label>
        <textarea id="datagramText" name="datagramText" rows="8" class="form-control"></textarea>
    </div>
    <p><input type="submit" class="btn btn-secondary" name="test" value="Test Datagram"/></p>

<h5>Parameters:</h5>
<table class="table table-bordered table-striped">
    <thead>
        <th scope="col">id</th>
        <th scope="col">index</th>
        <th scope="col">name</th>
        <th scope="col">uniformName</th>
        <th scope="col">length</th>
        <th scope="col">prefix</th>
        <th scope="col">postfix</th>
        <th scope="col">format</th>
        <th scope="col">description</th>
    </thead>
#{list items:parameters, as:'parameter' }
    <tr>
        <th scope="row">${parameter.selectSingleNode("id").getText()}</th>
        <td>${parameter.selectSingleNode("index").getText()}</td>
        <td>${parameter.selectSingleNode("name").getText()}</td>
        <td>${parameter.selectSingleNode("uniformName").getText()}</td>
        <td>${parameter.selectSingleNode("length").getText()}</td>
        <td><span class="text-muted">[</span>${parameter.selectSingleNode("prefix").getText()}<span class="text-muted">]</span></td>
        <td><span class="text-muted">[</span>${parameter.selectSingleNode("postfix").getText()}<span class="text-muted">]</span></td>
        <td>${parameter.selectSingleNode("format").getText()}</td>
        <td>${parameter.selectSingleNode("description").getText()}</td>
    </tr>
#{/list}
</table>

#{/form}


<hr>
<h5>Reformat Templates:</h5>

#{if entity}
<ul>
#{list items:entity.reformat_templates, as:"item"}

    <li>   <strong>${item.reformat_template_name}</strong>
        [<a href="@{controllers.Application.ta015xml(item.getId())}" target="_blank">Show Xml</a>]
        [<a href="@{controllers.ReformatTemplate.edit(item.getId(), entity.getId())}" target="_blank">Edit</a>]
        [<a href="@{controllers.ReformatTemplate.remove(item.getId())}">Remove</a>]
    </li>


<table class="table table-bordered table-striped">
    <thead>
    <th scope="col">name</th>
    <th scope="col">uniformName</th>
    <th scope="col">convertId</th>
    <th scope="col">format</th>
    <th scope="col">parameter</th>
    <th scope="col">length</th>
    <th scope="col">scription</th>
    <th scope="col">fillType</th>
    <th scope="col">fillString</th>
    <th scope="col">trimType</th>
    </thead>
    %{
        units = reformatTemplates.get(item.reformat_template_name)
        for (unit in units) {
    }%
        <tr>
            <th scope="row">${unit.attribute("name").getText()}</th>
            <td>${unit.selectSingleNode("uniformName").getText()}</td>
            <td>${unit.selectSingleNode("convertId").getText()}</td>
            <td>${unit.selectSingleNode("format").getText()}</td>
            <td>${unit.selectSingleNode("parameter").getText()}</td>
            <td>${unit.selectSingleNode("length").getText()}</td>
            <td>${unit.selectSingleNode("scription").getText()}</td>
            <td>${unit.selectSingleNode("fillType").getText()}</td>
            <td>${unit.selectSingleNode("fillString").getText()}</td>
            <td>${unit.selectSingleNode("trimType").getText()}</td>
        </tr>
    %{
        }
    }%
</table>
#{/list}
</ul>
#{/if}
    <hr>

<h5>Aircrafts</h5>
#{if entity}
#{tb005_table items:entity.getAircrafts() /}
#{/if}
</div>